#include "ModelComponent.h"
#include <wx/datetime.h>  // 确保包含这个头文件

CModelComponent::CModelComponent(const ComponentMetadata& metadata, const wxString& content)
    : m_metadata(metadata), m_content(content)
{
    if (!m_metadata.createdAt.IsValid()) {
        m_metadata.createdAt = wxDateTime::Now();
    }
    m_metadata.lastModified = wxDateTime::Now();
}

bool CModelComponent::Validate() const
{
    if (m_metadata.name.IsEmpty()) return false;
    if (m_content.IsEmpty()) return false;
    if (m_metadata.version.IsEmpty()) return false;
    
    return true;
}

wxString CModelComponent::GetExportFormat() const
{
    wxString exportData;
    exportData << "COMPONENT:" << m_metadata.name << "\n";
    exportData << "VERSION:" << m_metadata.version << "\n";
    exportData << "AUTHOR:" << m_metadata.author << "\n";
    exportData << "DESCRIPTION:" << m_metadata.description << "\n";
    exportData << "CONTENT:\n" << m_content << "\n";
    return exportData;
}

bool CModelComponent::CheckCompatibility(const CModelComponent& other) const
{
    for (const auto& dep : m_metadata.dependencies) {
        if (dep == other.GetMetadata().name) {
            return true;
        }
    }
    return false;
}

void CModelComponent::UpdateVersion(const wxString& newVersion)
{
    m_metadata.version = newVersion;
    m_metadata.lastModified = wxDateTime::Now();
}

void CModelComponent::AddDependency(const wxString& componentName)
{
    m_metadata.dependencies.push_back(componentName);
}
